﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Boomerang.Common.Tracing
{
    public class BoomerangEventLogListener : TraceListener
    {
        const string source = "BoomerangService";
        private EventLogTraceListener eventLogListener = new EventLogTraceListener(source);

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
        {
            if ( (eventType== TraceEventType.Critical) || ( eventType == TraceEventType.Error) || (eventType == TraceEventType.Warning))
            base.TraceEvent(eventCache, source, eventType, id);
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if ( (eventType== TraceEventType.Critical) || ( eventType == TraceEventType.Error) || (eventType == TraceEventType.Warning))
            eventLogListener.TraceEvent(eventCache, source, eventType, id, format, args);            
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            if ((eventType == TraceEventType.Critical) || (eventType == TraceEventType.Error) || (eventType == TraceEventType.Warning))
            eventLogListener.TraceEvent(eventCache, source, eventType, id, message);
        }

        public override void Write(string message)
        {
            eventLogListener.Write(message);
        }

        public override void WriteLine(string message)
        {
            eventLogListener.WriteLine(message);
        }
    }
}
